import _thread as thread
import time

stdoutmutex = thread.allocate_lock()

exitmutexes = [False] * 10


def counter(myId, count):
    for i in range(count):
        stdoutmutex.acquire()
        print('[%s] => %s' % (myId, i))
        stdoutmutex.release()
    exitmutexes[myId] = True


for i in range(10):
    thread.start_new_thread(counter, (i, 10000))

while False in exitmutexes:
    time.sleep(0.01)

print('Main thread exiting...')
